﻿//-----------------------------------------------------------------------------------------//
//-     Writen by Raymond Honderdors
//-     2013-05-14
//-
//-     Code can be used as is, no warrenty
//-     https://solutionmanagementki.codeplex.com/
//-----------------------------------------------------------------------------------------//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AnalysisServices;
namespace SMK_SSAS
{
    /// <summary>
    /// 
    /// </summary>
    public class AMO_Traces
    {
        /// <summary>
        /// 
        /// </summary>
        public Microsoft.AnalysisServices.Trace amotrace = null;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Server"></param>
        /// <param name="TraceID"></param>
        public void SetAMOTrace(AMO_Server Server, string TraceID)
        {
            if (Server != null && Server.Isconnected())
            {
                if (Server.amoserver().Traces.Contains(TraceID))
                {
                    amotrace = Server.amoserver().Traces.Find(TraceID);
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean HasEvents()
        {
            if (amotrace != null)
            {
                if (amotrace.Events.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> Events()
        {
            SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
            foreach (Microsoft.AnalysisServices.TraceEvent db in amotrace.Events)
            {
                AMO_Key amok = new AMO_Key();
                amok.ID = db.EventID.ToString();
                amok.Name = db.EventID.ToString();
                result.Add(amotrace.Name + "\\" + db.EventID.ToString(), amok);
            }
            return result;
        }
    }
}
